#include <iostream>
#include <stdio.h>
#include <string.h>
#define MaxSize 105
using namespace std;
struct Node
{
    int k;
    int leaf[MaxSize];
};
int layer;
int leafCount[MaxSize];
Node *nodes[MaxSize];
void bfs()
{
    int seq[MaxSize];
    int front = 0, end = 0;
    int k, l; //当前层和下一层的结点个数
    Node *t;
    layer = 0;
    seq[end] = 1;
    end = (end + 1) % MaxSize;
    k = 1;
    l = 0;
    while (front != end)
    {
        t = nodes[seq[front]];
        front = (front + 1) % MaxSize;
        if (t->k == 0)
        {
            leafCount[layer]++;
        }
        else
        {
            l += t->k;
            for (int i = 0; i < t->k; i++)
            {
                seq[end] = t->leaf[i];
                end = (end + 1) % MaxSize;
            }
        }
        k--;
        if (k == 0)
        {
            layer++;
            k = l;
            l = 0;
        }
    }
}
int main()
{
    memset(leafCount, 0, sizeof(leafCount));
    for (int i = 0; i < MaxSize; i++)
    {
        nodes[i] = new Node();
        nodes[i]->k = 0;
    }
    int n, m, k;
    int num;
    cin >> n >> m;
    if (n == 0)
        return 0;
    Node *n1;
    for (int i = 0; i < m; i++)
    {
        cin >> num >> k;
        n1 = nodes[num];
        n1->k = k;
        for (int j = 0; j < n1->k; ++j)
        {
            cin >> n1->leaf[j];
        }
    }
    bfs();
    for (int i = 0; i < layer; i++)
    {
        if (i != 0)
            cout << " " << leafCount[i];
        else
            cout << leafCount[i];
    }
    return 0;
}